using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace Test {
	class Bb {
		static void MainX() {

			ZCache ch=new ZCache("bb");
			//ch.Sql.NonQry("drop table bb");
			//ch.Sql.NonQry("create table bb(id int identity,ekey varchar(20) unique,inserted datetime default getdate(),lastUpdate datetime default getdate(),title varchar(200))");
			string cont=ch.Get(ch["main"],250);
			string[] tabs=Nod.Dbls(cont,"<table r=");
			if(tabs.Length==0)
				tabs=Nod.Dbls(cont,"<table listingId=");
			foreach(string tab in tabs)
			{
				string id=Nod.Rx(tab,"iid=\"(.+?)\"");
				if((int)ch.Sql.NonQry("update bb set lastUpdate=getdate() where ekey='{0}'",id)==0)
				{
					string title=Nod.Rx(tab,"title='(.+?)'");
					ch.Sql.NonQry("insert into bb(ekey,title)values('{0}','{1}')",id,title);
					Console.WriteLine(id);
				}
			}
		}
		static void MainZ() {
			ZCache ch=new ZCache("bb");

			DataTable tab=ch.Sql.Query("select ekey from bb where endtime<getdate() and sold is null");
			foreach(DataRow row in tab.Rows)
			{
				string cont="";
				try
				{
					cont=ch.Get(ch["itm"]+row[0],50);
				}
				catch(Exception ex)
				{
					ch.Sql.NonQry("update bb set sold=-1 where ekey={0}",row[0]);
				}
				string pri=Nod.Rx(cont,"<span id=\"\" class=\"notranslate vi-VR-cvipPrice\">.(.+?)</span>");
				float fpri;
				if(float.TryParse(pri,out fpri))
				{
					fpri*=100;
					int ipri=(int)fpri;
					ch.Sql.NonQry("update bb set sold={0} where ekey={1}",ipri,row[0]);
				}
			}



		}
	}
}
